package com.pgybook.db.entity.mapper;

import org.springframework.stereotype.Repository;
import com.pgybook.db.entity.domain.Advice;
import com.pgybook.db.entity.domain.AdviceEx;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectKey;
import org.apache.ibatis.annotations.Update;

@Repository
public interface AdviceMapper {
    int countByExample(AdviceEx example);

    int deleteByExample(AdviceEx example);

    @Delete({
            "delete from advice",
            "where ADVICEID = #{adviceid,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer adviceid);

    @Insert({
            "insert into advice (CUSTID, TITILE, ",
            "TYPE, ISCUSTMOR, IPADDRESS, ",
            "CONTENT, STATUS, ",
            "CRTTIME, HANDLESTAFF, ",
            "HANDLETIME)",
            "values (#{custid,jdbcType=BIGINT}, #{titile,jdbcType=VARCHAR}, ",
            "#{type,jdbcType=INTEGER}, #{iscustmor,jdbcType=BIT}, #{ipaddress,jdbcType=VARCHAR}, ",
            "#{content,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, ",
            "#{crttime,jdbcType=TIMESTAMP}, #{handlestaff,jdbcType=INTEGER}, ",
            "#{handletime,jdbcType=TIMESTAMP})"
    })
    @SelectKey(statement = "SELECT LAST_INSERT_ID()", keyProperty = "adviceid", before = false, resultType = Integer.class)
    int insert(Advice record);

    int insertSelective(Advice record);

    List<Advice> selectByExample(AdviceEx example);

    @Select({
            "select",
            "ADVICEID, CUSTID, TITILE, TYPE, ISCUSTMOR, IPADDRESS, CONTENT, STATUS, CRTTIME, ",
            "HANDLESTAFF, HANDLETIME",
            "from advice",
            "where ADVICEID = #{adviceid,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    Advice selectByPrimaryKey(Integer adviceid);

    int updateByExampleSelective(@Param("record") Advice record, @Param("example") AdviceEx example);

    int updateByExample(@Param("record") Advice record, @Param("example") AdviceEx example);

    int updateByPrimaryKeySelective(Advice record);

    @Update({
            "update advice",
            "set CUSTID = #{custid,jdbcType=BIGINT},",
            "TITILE = #{titile,jdbcType=VARCHAR},",
            "TYPE = #{type,jdbcType=INTEGER},",
            "ISCUSTMOR = #{iscustmor,jdbcType=BIT},",
            "IPADDRESS = #{ipaddress,jdbcType=VARCHAR},",
            "CONTENT = #{content,jdbcType=VARCHAR},",
            "STATUS = #{status,jdbcType=INTEGER},",
            "CRTTIME = #{crttime,jdbcType=TIMESTAMP},",
            "HANDLESTAFF = #{handlestaff,jdbcType=INTEGER},",
            "HANDLETIME = #{handletime,jdbcType=TIMESTAMP}",
            "where ADVICEID = #{adviceid,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(Advice record);
}
